package com.kjlink.internal.workreport.group.service;

import cn.xuqiudong.common.base.lookup.Lookup;
import cn.xuqiudong.common.base.model.BaseResponse;
import cn.xuqiudong.common.base.model.PageInfo;
import cn.xuqiudong.common.base.service.BaseService;
import com.kjlink.internal.workreport.group.mapper.GroupMapper;
import com.kjlink.internal.workreport.group.model.Group;
import com.kjlink.internal.workreport.user.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 功能: :小组 Service
 *
 * @author Vic.xu
 * @since 2024-04-29 13:40
 */
@Service
public class GroupService extends BaseService<GroupMapper, Group> {

    @Resource
    private UserService userService;

    @Override
    protected boolean hasAttachment() {
        return false;
    }

    @Override
    public PageInfo<Group> page(Lookup lookup) {
        startPage(lookup.getPage(), lookup.getSize());
        List<Group> dataList = mapper.list(lookup);
        return PageInfo.instance(dataList, lookup);
    }

    public BaseResponse<String> checkAndDelete(int id) {
        int num = userService.checkUserNumberByGroupId(id);
        if (num > 0) {
            return BaseResponse.error("当前小组下上存在用户,不可删除");
        }
        return delete(id) > 0 ? BaseResponse.success() : BaseResponse.error();

    }
}
